//
//  FoundViewController.m
//  Found
//
//  Created by 唐后能 on 16/4/2.
//  Copyright © 2016年 itheima. All rights reserved.
//

#import "XBFindHeadViewController.h"
#import "XBOtherHead.h"
#import "XBHotClassView.h"
#import "XBUserHead.h"
#import "XBUserView.h"
#import "XBArtNameHead.h"
@interface XBFindHeadViewController ()

@property (nonatomic, weak) XBOtherHead *classHead;

@property (nonatomic, weak) UIView *hotClassView;

@property (nonatomic, weak) XBUserHead *userHead;

@property (nonatomic, weak) XBUserView *userView;

@property (nonatomic, weak) XBArtNameHead *artNameHead;

@end

@implementation XBFindHeadViewController
// 改变控制器的View为ScrollView.
-(void)loadView {

    self.view = [[UIScrollView alloc] init];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // 添加子控件.
    [self setupUI];
    // 设置背景.
    self.view.backgroundColor = [UIColor whiteColor];
    
    
    
}

// 添加子控件.
- (void)setupUI {
    
    // 1,添加热门分类Head.
    XBOtherHead *classHead = [XBOtherHead otherHead];
    [self.view addSubview:classHead];
    classHead.name = @"热门分类";
    self.classHead = classHead;
    
    // 2,添加热门分类View.
    XBHotClassView *hotClassView = [[XBHotClassView alloc] init];
    [self.view addSubview:hotClassView];
    self.hotClassView = hotClassView;

    // 3,添加热门用户组头.
    XBUserHead *userHead = [XBUserHead userHead];
    [self.view addSubview:userHead];
    self.userHead = userHead;
    
    // 4,添加热门用户Veiw
    XBUserView *userVeiw = [[XBUserView alloc]init];
    [self.view addSubview:userVeiw];
    self.userView = userVeiw;
    
    // 5,添加艺志铭Head.
    XBArtNameHead *artNameHead = [XBArtNameHead artNameHead];
    [self.view addSubview:artNameHead];
    self.artNameHead = artNameHead;
    
}

    


// 布局子控件.
-(void)viewDidLayoutSubviews {

    CGFloat screenW = [UIScreen mainScreen].bounds.size.width;
    CGFloat margin = 10;
    // 1,布局热门分类组头.
    CGFloat classHeadH = 30;
    CGFloat classHeadY = margin;
    self.classHead.frame = CGRectMake(margin, classHeadY, screenW-2*margin, classHeadH);
    
    // 2,布局hotClassView.
    CGFloat hotClassViewH = 250;
    CGFloat hotClassViewY = CGRectGetMaxY(self.classHead.frame)+ margin;
    self.hotClassView.frame = CGRectMake(margin, hotClassViewY, screenW-2*margin, hotClassViewH);

    // 3,布局UserHead.
    CGFloat userHeadH = 30;
    CGFloat userHeadY = CGRectGetMaxY(self.hotClassView.frame) + margin;
    self.userHead.frame = CGRectMake(margin, userHeadY, screenW-2*margin, userHeadH);
    
    // 4,布局userVeiw
    CGFloat userViewH = 250;
    CGFloat userViewY = CGRectGetMaxY(self.userHead.frame)+ margin;
    self.userView.frame = CGRectMake(margin, userViewY, screenW-2*margin, userViewH);
    
    // 5,添加艺志铭Head.
    CGFloat artNameHeadH = 30;
    CGFloat artNameHeadY = CGRectGetMaxY(self.userView.frame) + margin;
    self.artNameHead.frame = CGRectMake(margin, artNameHeadY, screenW-2*margin, artNameHeadH);
    
    // 打印最大Y值.
//    CGFloat maxY = CGRectGetMaxY(self.artNameHead.frame) + margin;
//    NSLog(@"%lf",maxY);
    
}


@end
